package com.yunji.ylexpiration.service.impl;

import com.yunji.ylexpiration.entity.FurnOrders;
import com.yunji.ylexpiration.entity.FurnOrdersExample;
import com.yunji.ylexpiration.mapper.FurnOrdersMapper;
import com.yunji.ylexpiration.service.FurnOrdersMapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FurnOrdersMapperServiceimpl implements FurnOrdersMapperService {

    @Autowired
    FurnOrdersMapper furnOrdersMapper;
    @Override
    public int FurnOrdersadd(FurnOrders furnOrders) {
        if (null==furnOrders){
            return 0;
        }
        int i = furnOrdersMapper.insertSelective (furnOrders);
        return i;
    }

    @Override
    public int upFurnOrders(FurnOrders furnOrders) {
        if (null==furnOrders) return 0;
        int i = furnOrdersMapper.updateByPrimaryKeySelective2 (furnOrders);
        return i;
    }

    @Override
    public List<FurnOrders> selFurnOrders(Integer userid) {
        if (null==userid){
            return null;
        }
        FurnOrdersExample example = new  FurnOrdersExample();
        FurnOrdersExample.Criteria criteria = example.createCriteria ();
        criteria.andUserIdEqualTo (userid);
        return furnOrdersMapper.selectByExample (example);
    }

    @Override
    public List<FurnOrders> selFurnOrdersbyStatus(String Status, Integer Userid) {
        FurnOrdersExample example=new FurnOrdersExample ();
        FurnOrdersExample.Criteria criteria = example.createCriteria ();
        criteria.andUserIdEqualTo (Userid);
        criteria.andOrderStatusEqualTo (Status);
        List<FurnOrders> furnOrders = furnOrdersMapper.selectByExample (example);
        return furnOrders;
    }
    @Override
    public FurnOrders selFurnOrdersnum(String orderNum) {
        if (null==orderNum){
            return null;
        }
        FurnOrdersExample example=new FurnOrdersExample ();
        FurnOrdersExample.Criteria criteria = example.createCriteria ();
        criteria.andOrderNumEqualTo (orderNum);
        return furnOrdersMapper.selectByExample (example).get (0);
    }

    @Override
    public List<FurnOrders> countByorder(String status,Integer userId) {
        FurnOrdersExample example = new FurnOrdersExample();
        FurnOrdersExample.Criteria criteria = example.createCriteria();
        criteria.andOrderStatusEqualTo(status);
        criteria.andUserIdEqualTo(userId);
        List<FurnOrders> furnOrders = furnOrdersMapper.selectByExample(example);
        if(furnOrders==null||furnOrders.size()==0){
            return null;
        }
        return furnOrders;
    }
}
